from django.db import models

import django.contrib.auth.models
from django.contrib.auth.models import AbstractUser
from django.utils.translation import gettext_lazy as _


class MyUser(AbstractUser):
    email = models.EmailField(_('email address'), blank=True, unique=True)
    USERNAME_FIELD = 'email'  # 管理员使用email登陆
    REQUIRED_FIELDS = ['username']  # 管理员使用email登陆

    class Meta:
        verbose_name = '基础员工信息'
        verbose_name_plural = verbose_name


django.contrib.auth.models.User = MyUser


class StaffProfile(models.Model):

    STAFF_STATUS_CHOICES = (
        ('ok', '正常'),
        ('abnormal', '异常用户'),
    )

    user = models.ForeignKey(
        MyUser,
        on_delete=models.SET_NULL,
        default=None,
        null=True,
    )

    cellphone = models.CharField(
        '手机',
        max_length=30,
        help_text='手机',
        db_index=True,
        default='',
    )

    def __str__(self):
        return self.user.username

    class Meta:
        verbose_name = '员工信息'
        verbose_name_plural = verbose_name
